import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:laos_mall/common/style/app_style.dart';
import 'package:laos_mall/common/style/extension_util.dart';
import 'package:laos_mall/common/utils/widget_util.dart';
import 'package:laos_mall/common/widght/mall/zb_Item_widget.dart';
import 'package:laos_mall/pages/main/config.dart';

import 'logic.dart';

class PayPage extends StatelessWidget {
  PayPage({Key? key}) : super(key: key);

  final logic = Get.put(PayLogic());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PayLogic>(builder: (logic) {
      return Scaffold(
        appBar: AppBar(),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            _buildHeader(),
            _buildPayType(),
            _buildPrompt(),
            AppButton.sizeBtn(() { }, "pay_now".tr,size: Size(180.w, 40.h)).addContainer(margin: EdgeInsets.only(top: 29.h))
          ],
        ),
      );
    });
  }

  _buildHeader() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        Text(
          Config.symbol + "179.00",
          style: AppStyle.textStyle
              .copyWith(fontSize: 30.sp, fontWeight: FontWeight.bold),
        ),
        Text('order_number'.tr + ":${12141242412}",style: AppStyle.subtitleLightStyle,),
      ],
    ).addContainer(
        height: 110.w, color: Colors.transparent, width: double.infinity);
  }

  _buildPayType() {
    return ListView.builder(
      itemBuilder: (context, index) {
        var item = logic.payTypes[index];
        return ZBItemWidget(
          style: ZBItemStyle.selectCircle,
          prefixItem: Row(
            children: [
              Image.asset(logic.imageNames[index].toImgPath(),
                  width: 30.w, height: 30.w),
              SizedBox(
                width: 10.w,
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  if (item.defaultValue == false)
                    Row(
                      children: [
                        Text(
                          item.label.tr,
                          style: AppStyle.textStyle.copyWith(
                              color: item.checked
                                  ? Colors.white
                                  : AppColor.textColor),
                        ),
                        SizedBox(
                          width: 3.w,
                        ),
                        Text(
                          "(INSUFFICIENT BALANCE)",
                          style: AppStyle.textSmallStyle.copyWith(
                              color: "#FF2922".toColor, fontSize: 9.sp),
                        )
                      ],
                    ),
                  if (item.defaultValue != false)
                    Text(
                      item.label.tr,
                      style: AppStyle.textStyle.copyWith(
                          color:
                              item.checked ? Colors.white : AppColor.textColor),
                    ),
                  Text(
                    "subttile",
                    style: AppStyle.textSmallStyleLightGray,
                  )
                ],
              )
            ],
          ),
          isSel: item.checked,
        )
            .addContainer(
                color:
                    item.checked ? AppColor.primaryColor : Colors.transparent,
                height: 54.h,
                padding: EdgeInsets.only(left: 22.w, right: 10.w))
            .addGestureTap(() {
              if(item.defaultValue == false) return;
          for (var element in logic.payTypes) {
            element.checked = false;
          }
          item.checked = true;
          logic.update();
        }).addOpacity(item.defaultValue == false ? 0.3 : 1);
      },
      shrinkWrap: true,
      padding: EdgeInsets.zero,
      itemCount: logic.payTypes.length,
    );
  }

  _buildPrompt() {
    return WidgetUtil.getHeaderInfo(
            "additional_information".tr,
            Text(
              "PAYMENT METHOD: ONLINE PAYMENT DELIVERY OPTIONS: EXPRESS DELIVERY ORDER TIME: 2025-02-24 11:59:22",
              style: AppStyle.textSmallStyleLightGray,
            ))
        .addContainer(width: double.infinity,padding: EdgeInsets.only(top: 12.h,left: 30.w));
  }
}
